import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;


	public class VendingMachineTest {
		VendingMachine VendengMachine;
		VendingMachineItem test1;

	@Before
	public void setUp() throws Exception 
	{
		VendengMachine =new VendingMachine();
		test1 = new VendingMachineItem("juice",1.00);
	}

	@Test		
	public void AddItemTest() 
	{
		VendengMachine.addItem( test1,VendingMachine.A_CODE);// add item into first slot
		assertEquals(test1, VendengMachine.getItem(VendingMachine.A_CODE ));
		assertNull(VendengMachine.getItem(VendingMachine.B_CODE));
		assertNull(VendengMachine.getItem(VendingMachine.C_CODE));
		assertNull(VendengMachine.getItem(VendingMachine.D_CODE));
	}

	@Test
	public void RemoveItemTest()
	{
		VendengMachine.addItem(test1,VendingMachine.A_CODE);
		VendengMachine.removeItem(VendingMachine.A_CODE); // Remove Item from first slot
		assertEquals(null,VendengMachine.getItem(VendingMachine.A_CODE )); 
	}

	@Test
	public void InsertMoneyTest()
	{
		VendengMachine.insertMoney(1.00);
		assertEquals(1.00, VendengMachine.getBalance(), 1.00);
		// Bug one: the machine accept inserting amount of 0
	}

	@Test
	public void GetBalanceTest()
	{
		VendengMachine.balance=3;
		assertEquals(3,VendengMachine.getBalance(),3);
	}

	@Test
	public void MakePurchaseTest()
	{
		VendengMachine.addItem(test1,VendingMachine.A_CODE);
		VendengMachine.balance=2.0;
		assertEquals(true,VendengMachine.makePurchase(VendingMachine.A_CODE));
		assertEquals(false,VendengMachine.makePurchase(VendingMachine.C_CODE)); // return false if slot is empty
	}

	@Test
	public void ReturnChangeTest()
	{
		VendengMachine.insertMoney(3.00); // insert money, add item, make purchase then return change
		VendengMachine.addItem(test1, VendingMachine.A_CODE);
		VendengMachine.makePurchase(VendingMachine.A_CODE);
		assertEquals(3.00-test1.getPrice(),VendengMachine.returnChange(),0.01);
	}
}
